package com.ls.pattern.prototype.shallow;

import cn.hutool.core.bean.BeanUtil;
import com.ls.pattern.common.util.DeepCloneUtil;
import org.springframework.beans.BeanUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author liushuang
 * @version 1.0.0
 * @date 2023/10/7 17:33
 */
public class Test {

    public static void main(String[] args) {
        User user = new User();
        user.setName("张三");
        user.setAge(18);
        user.setPhone(new Phone());

        User user1 = new User();
        user1.setName("李四");
        user1.setAge(19);
        user1.setPhone(new Phone());

        List<User> list = Arrays.asList(user, user1);
        List<User> cloneList = DeepCloneUtil.cloneList(list, User.class);
        System.out.println();
    }

    public void test1() {
        ShallowPerson shallowPerson = new ShallowPerson();
//        Phone phone = new Phone();
//        phone.setPhoneNumber("12312312");
//        shallowPerson.setPhone(phone);
        Phone phone = new Phone();
        phone.setPhoneNumber("12312312");
        shallowPerson.setPhones(Collections.singletonList(phone));

        ShallowPerson shallowPerson1 = new ShallowPerson();
        BeanUtils.copyProperties(shallowPerson, shallowPerson1);

        ShallowPerson shallowPerson2 = new ShallowPerson();
        BeanUtil.copyProperties(shallowPerson, shallowPerson2);

        ShallowPerson shallowPerson3 = BeanUtil.copyProperties(shallowPerson, ShallowPerson.class);
        ShallowPerson shallowPerson4 = BeanUtil.toBean(shallowPerson, ShallowPerson.class);

        ShallowPersonDTO shallowPersonDTO = new ShallowPersonDTO();
        BeanUtils.copyProperties(shallowPerson, shallowPersonDTO);

        ShallowPersonDTO shallowPersonDTO1 = BeanUtil.copyProperties(shallowPerson, ShallowPersonDTO.class);

        System.out.printf("shallowPerson1: %s\n", shallowPerson1);

//        PropertyUtils.copyProperties(shallowPersonDTO, shallowPerson);
//        System.out.println(shallowPersonDTO);
    }
}
